package org.example.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfig {

    // 声明交换机
    @Bean
    public DirectExchange stockZeroExchange() {
        return new DirectExchange("stock-zero-exchange");
    }

    // 声明队列
    @Bean
    public Queue stockZeroQueue() {
        return new Queue("stock-zero-queue");
    }

    // **绑定队列到交换机**
    @Bean
    public Binding stockZeroBinding(Queue stockZeroQueue, DirectExchange stockZeroExchange) {
        return BindingBuilder.bind(stockZeroQueue).to(stockZeroExchange).with("stock.zero");
    }
}

